package com.rpc.loadBalancer;

import com.alibaba.nacos.api.naming.pojo.Instance;

import java.util.List;

/**
 * 轮询负载均衡
 * @author ZhangYongLiang
 * @Date 2021/11/15 10:58
 */
public class RoundRobinLoadBalancer implements LoadBalancer {

    private int index = 0;

    @Override
    public Instance select(List<Instance> instances) {
        if (index >= instances.size()) {
            index = index % instances.size();
        }
        return instances.get(index);
    }
}
